<template>
  <div :bordered="false">
    <!-- table区域-begin -->
    <div>
      <vxe-grid
        id="RoleWithinDeptList"
        keep-source
        ref="vxeTable"
        :height="height"
        v-bind="options"
        :pagerConfig="false"
        @checkbox-change="onSelectChange"
        @checkbox-all="onSelectChange"
        @page-change="handlePageChange"
      >
      <template #action="{ row }">
        <template>
          <a @click="handleDelete(row.id)" >删除</a>
        </template>
      </template>
    </vxe-grid>
    </div>
    <!-- table区域-end -->
    <RoleWithoutDeptModal :roleId="roleId" ref="modalForm" @ok="modalFormOk" />
  </div>
</template>

<script>
import { VxeTableMixin } from '@/mixins/VxeTableMixin'
import RoleWithoutDeptModal from './RoleWithoutDeptModal'
import { roleDelActors } from '@/services/system'
export default {
  name: 'RoleWithinDeptList',
  components: {
    RoleWithoutDeptModal
  },
  props: {
    roleId: {
      type: String
    }
  },
  mixins: [VxeTableMixin],
  data() {
    return {
      columns: [
        { type: 'checkbox', width: 40 },
        { type: 'seq', width: 80 },
        {
          title: '部门编码',
          align: 'center',
          field: 'deptCode'
        },
        {
          title: '部门名称',
          align: 'center',
          field: 'deptName'
        },
        {
          title: '操作',
          slots: { default: 'action' },
          align: 'center',
          width: 120
        }
      ],
      url: {
        list: ''
      },
      // 查询参数
      queryParam: {},
      selectedRowKeys: [],
      selectedRows: [],
      toggleSearchStatus: false,
      disableMixinCreated: true,
      customTableToolbar: {
        export: false,
        print: false
      }
    }
  },
  watch: {
    roleId: {
      handler(val) {
        if (val) {
          this.url.list = `/dept/role/within/${val}`
          this.loadData()
          // this.setTableHeight()
        } else {
          this.dataSource = []
        }
      },
      immediate: true
    }
  },
  methods: {
    batchDel() {
      roleDelActors(this.roleId, this.selectedRowKeys).then(res => {
        if (res.success) {
          this.loadData(1)
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    handleDelete(actorId) {
      roleDelActors(this.roleId, [actorId]).then(res => {
        if (res.success) {
          this.loadData(1)
        } else {
          this.$message.warning(res.message)
        }
      })
    }
  }
}
</script>

